#include "customtimer.h"

CustomTimer::CustomTimer(QObject *parent)
    :QObject(parent)
{

}

//tv_sec提供秒级精度，tv_usec提供微秒级精度，以值大的为先，注意1s = 1000000ms。
void CustomTimer::start(long millisecond)
{
    bool flag = true;

    struct timeval tv;
    tv.tv_sec = 0;
    tv.tv_unsec = millisecond;

    while(flag)
    {
        int result = select(0, NULL, NULL, NULL, &tv);
        switch (result) {
        case -1:
            flag = false;
            break;
        case 0:
            emit timeout();
            break;
        default:
            break;
        }
    }
}
